/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.aurelius;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.testng.annotations.Test;

/**
 *
 */
public class JpaStarter {

    @Test(enabled=false)
    public void main() throws InterruptedException {

        EntityManagerFactory emf =
                Persistence.createEntityManagerFactory("embedded-hsql-persistance-unit");
        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();

        SimplePojo simpleEntity1 = new SimplePojo(1 , "cos");
        SimplePojo simpleEntity2 = new SimplePojo(2 , "cos innego");

        em.persist(simpleEntity1);
        em.persist(simpleEntity2);

        em.getTransaction().commit();
//        Query createQuery = em.createNativeQuery("Select count(*) from Cos");
//        Object singleResult = createQuery.getSingleResult();
//
//        System.out.println(singleResult);

        SimplePojo find = em.find(SimplePojo.class, 2);

        System.out.println(find);

        em.close();
        emf.close();

    }
}
